package collect;

import java.io.FileOutputStream;
import java.util.*;
import java.util.Collection;


public class Demo2 {
    public static void main(String[] args){
        Collection<Point> points1=new ArrayList<>();////创建集合对象
        List<Point> points2=(List<Point>) points1;//创建了List接口
        ArrayList<Point> points3=(ArrayList<Point>)points1;//实例化了ArrayList对象，继承了上两个接口
        points1.add(new Point(3,5));//向列表的尾部添加指定的元素
        points2.add(0, new Point(8,2));
        points3.add(new Point(10,5));
        Object[] arrp=points1.toArray();
        for (Object p:arrp){
            System.out.println((Point)p+"==>");
        }
        Point[] arr=new Point[points2.size()];
        arr=points1.toArray(arr);
        for (Point p:arr){
            System.out.println(p+"****");
        }
        ArrayList<Point> p1=new ArrayList<>();//创建集合对象
        Point pt1=new Point(100,120);
        Point pt2=new Point(100,120);
        Point pt3=new Point(100,120);
        p1.add(pt1);//给集合中添加一个点对象
        p1.add(pt2);
        System.out.println(pt1.hashCode());
        System.out.println(pt2.hashCode());
        System.out.println(p1.contains(pt3));
        points1.addAll(p1);//points1放到p1
        Iterator<Point> its=points1.iterator();
        while (its.hasNext()){
            System.out.println(its.next());
        }
        System.out.println("---------**********");
        for (Point p:points1){
            System.out.println(p);
        }
        System.out.println("-------------");
        for (Point p:points2){
            System.out.println(p);
        }
        System.out.println("-------------");
        for (Point p:points3){
            System.out.println(p);
        }
//        ArrayList<Integer> al = new ArrayList<Integer>();
//        al.add(new Integer(1));
//        al.add(new Integer(2));
//        al.add(new Integer(3));
//        al.add(new Integer(4));
//        al.add(new Integer(5));
//        System.out.println("al中元素:" + al);
////获得数组
//        Object ia[] = al.toArray();
////遍历数组
//        for(int i=0; i<ia.length; i++){
//            System.out.println(ia[i] + " ");
//        }
//
//        List<String> staff = new LinkedList<>();
//        staff.add("张三");
//        staff.add("孙悟空");
//        staff.add("猪八戒");
//        ListIterator<String> iter = staff.listIterator();
//        String first = iter.next();
//
//        //删除zhuwei
//        iter.remove();
//
//        //把张三改为李四
//        //iter.set("李四");
//        System.out.println("first:"+first);
//
//        iter.add("李四");
//
//        //遍历List元素
//        System.out.println("遍历List中元素，方法一：");
//        for(String str : staff)
//            System.out.println(str+"   ");
//
//        iter = staff.listIterator();
//        System.out.println("遍历List中元素，方法二：");
//        while(iter.hasNext())
//        {
//            System.out.println(iter.next());
//        }
    }
}




class Point{
    private int x;
    private int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    @Override
    public String toString() {
        return "点{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

}